package com.xiangyueEducation.uploaderCloud.service.entity.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiangyueEducation.uploaderCloud.mapper.UserMapper;
import com.xiangyueEducation.uploaderCloud.mapper.mapperUtil.ChatMapperUtil;
import com.xiangyueEducation.uploaderCloud.pojo.entity.Chat;
import com.xiangyueEducation.uploaderCloud.service.entity.ChatService;
import com.xiangyueEducation.uploaderCloud.mapper.ChatMapper;
import com.xiangyueEducation.uploaderCloud.service.util.ChatServiceUtil;
import com.xiangyueEducation.uploaderCloud.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author 86136
* @description 针对表【chat】的数据库操作Service实现
* @createDate 2024-12-19 10:51:57
*/
@Service
public class ChatServiceImpl extends ServiceImpl<ChatMapper, Chat>
    implements ChatService{
    @Resource
    ChatMapper chatMapper;
    @Resource
    UserMapper userMapper;
    @Autowired
    ChatMapperUtil chatMapperUtil;
    @Autowired
    ChatServiceUtil chatServiceUtil;

    /**
     *{
     *     history:[],
     *     page:{
     *          total: num,
     *          current: num
     *     }
     *}
     */
    @Override
    public Result<?> getHistory(Long senderId, Long receiverId, Page<Chat> page) {
        Page<Chat> historyPage = chatMapperUtil.getHistoryPage(senderId, receiverId, page);
        List<Map<String, Object>> chatContent = chatServiceUtil.toStandard(historyPage.getRecords(), senderId);
        return Result.ok(Map.of("history",chatContent,
                "page",
                Map.of("total",historyPage.getPages(),
                        "current",historyPage.getCurrent())));
    }
}




